<template>
  <!-- 输入表单 -->
  <el-form label-width="120px" style="margin: 30px">
    <el-form-item label="借款额度">
      <el-input-number v-model="integralGrade.borrowAmount" :min="0"/>
    </el-form-item>
    <el-form-item label="积分区间开始">
      <el-input-number v-model="integralGrade.integralStart" :min="0"/>
    </el-form-item>
    <el-form-item label="积分区间结束">
      <el-input-number v-model="integralGrade.integralEnd" :min="0"/>
    </el-form-item>
    <el-form-item>
      <el-button
        :disabled="saveBtnDisabled"
        type="primary"
        @click="saveOrUpdate()"
      >提交
      </el-button
      >
    </el-form-item>
  </el-form>
</template>

<script>
import integralgradeApi from "@/api/integralgrade";

export default {
  data() {
    return {
      saveBtnDisabled: false, //提交按钮是否禁用
      integralGrade: {},
    };
  },
  created() {
    if (this.$route.params.id) {
      integralgradeApi.getById(this.$route.params.id).then((r) => {
        this.integralGrade = r.data.item;
      })
    }
  },
  methods: {
    saveOrUpdate() {
      if (this.$route.params.id) {
        this.update();
      } else {
        this.save();
      }
    },
    save() {
      integralgradeApi.save(this.integralGrade).then((r) => {
        this.$message.success("新增成功");
        this.$router.push("/integral-grade/list");
      });
    },
    update() {
      integralgradeApi.updateById(this.integralGrade).then((r) => {
        this.$message.success("更新成功");
        this.$router.push("/integral-grade/list");
      })
    }
  },
};
</script>
